﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SmartProject.Entity;
using SmartProject.Exceptions;

using NHibernate;

namespace SmartProject.BusinessRules
{
    public class EmailAsUsername : BusinessRule
    {
        public override string Name
        {
            get { return "E-Mail address as username"; }
        }

        public override string Description
        {
            get { return "Username is the E-Mail address."; }
        }

        public override void Implement(ISession session, EntityBase entity)
        {
            if (entity.GetOperation() == EntityBase.Operations.Save)
            {
                User user = (User)entity;
                user.Username = user.Email;
            }
        }

        public override bool QueryBooleanProperty(string propertyName)
        {
            switch (propertyName)
            {
                case "IsEnableUserNameTextBox":
                    return false;
            }
            throw new MissingPropertyName(String.Format(
                "Property name is missing: {0}", propertyName));
        }
    }
}
